﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using FOModels.Product;
using System.Data;
namespace DataAccess.Product
{
    public class ProductDAL
    {
        private SQLDataAccess db;
        public ProductDAL()
        {
            db = new SQLDataAccess();
        }
        // Lấy top 3 loại tin có tin nhiều nhất
        public DataTable gettop3catebynews(int langid)
        {
            return db.exeSelect("select TOP 3  pc.ProductCID,pcl.Name from ProductCategory pc join ProductCategoryLang pcl on pc.ProductCID = pcl.ProductCID join Product p on pc.ProductCID = p.ProductCID join News n on p.ProductID = n.ProductID where n.Enable= 1 and p.Publish = 1 and pcl.LangID = "+langid+" group by  pcl.Name ,pc.ProductCID order by COUNT(pcl.Name) desc");
        }
        public DataTable getProductbyID(int ProductID, int langid)
        {
            return db.exeSelect("Select * from Product p join ProductLang pl on p.ProductID = pl.ProductID where p.ProductID=" + ProductID + " and LangID = " + langid + "");
        }
        public DataTable getProductby(int langid)
        {
            return db.exeSelect("Select p.ProductID,pl.ProductName from Product p join ProductLang pl on p.ProductID = pl.ProductID where LangID = " + langid + " and Publish ='1'");
        }
        public int UpdateProductDesriptionLang(ProductModels models, int langid)
        {
            return db.exeUpdate("update ProductLang set Description = N'" + models.Description + "' where ProductID = " + models.ProductID + " and LangID=" + langid + "");
        }

        public DataTable getProductCate(int langid)
        {
            return db.exeSelect("select pc.ProductCID,pcl.Name from ProductCategory pc join ProductCategoryLang pcl on pc.ProductCID =  pcl.ProductCID where pcl.LangID=" + langid + "");
        }

    }
}
